<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>API</title>
</head>
<script type="text/javascript" src="js/jquery-2.1.4.js"></script>
<script>

	function formToJson(formObj){
	   var o={};
	   var a=formObj.serializeArray();
	   $.each(a, function() {
	       if(this.value){
	           if (o[this.name]) {
	               if (!o[this.name].push) {
	                   o[this.name]=[ o[this.name] ];
	               }
	                   o[this.name].push(this.value || null);
	           }else {
	               if($("[name='"+this.name+"']:checkbox",formObj).length){
	                   o[this.name]=[this.value];
	               }else{
	                   o[this.name]=this.value || null;
	               }
	           }
	       }
	   });
	   return o;
	};
	
	$(document).ready(function() { 
	 
		//查询
	$(':button').click( function () {
		var url = $(this).parent().attr("action");
		var param  = formToJson($(this).parent());
		$.ajax({ 
				url: url, 
				type: "POST",
				data: JSON.stringify(param),
				dataType:"json",
				contentType:"application/json; charset=utf-8",
				success: function(data){
					var dataJson = JSON.stringify(data);
					alert(dataJson);
			}, error: function(request, error, status){  
				debugger
				alert('error...gx...error');
	            // todo: 错误处理  
	        }  });
		});
		
	});
</script>
<body>
	<fieldset>
    <div>
        <div>订购</div>
        <div>
            <form action="rest/1.2/order">
         			appkey:	<input  type="text" name="appkey" value="123"/> <br/>
         			timeStamp:<input  type="text" name="timeStamp" value="121321312"/> <br/>
                    sig: <input  type="text" name="sig" /><br/>
                	productId: <input  type="text" name="productId" value=""/><br/>
               		phoneNo: <input type="text" name="phoneNo" value="18699137752"/><br/>
               		cstmOrderNo: <input type="text" name="cstmOrderNo" value=""/><br/>
                <input type="button" value="发送"/>
            </form>
        </div>
    </div>
</fieldset>
<fieldset>
    <div>
        <div>查询状态</div>
        <div>
            <form action="rest/1.2/order/status">
         			appkey:	<input  type="text" name="appkey" value="123"/> <br/>
         			timeStamp:<input  type="text" name="timeStamp" value="121321312"/> <br/>
                    sig: <input  type="text" name="sig" /><br/>
                	cstmOrderNo: <input  type="text" name="cstmOrderNo" value=""/><br/>
                <input type="button" value="发送"/>
            </form>
        </div>
    </div>
</fieldset>
</body>
</html>